home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc™ Source Code / UI / WinUtilM.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  5.1 KB  |  209 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        WinUtilM.cpp
  3.  
  4.     Contains:    Utilities to manipulate Mac windows
  5.  
  6.     Owned by:    Richard Rodseth
  7.  
  8.     Copyright:    © 1994 - 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <8>      9/8/95    TÇ        1281096 FB2:Many constants in ODTypesB
  13.                                     without kOD prefix!
  14.          <7>     6/28/95    RR        1242642 BB Mostly ref counting. Add
  15.                                     WindowLink::ShouldRemove
  16.          <6>     6/22/95    RR        #1245283 Undoable frame deletion
  17.                                     #1209427 Changed private api between
  18.                                     iterator and iteratee. Allow deletion while
  19.                                     iterating. Added fRemove flag to WindowLink
  20.          <5>     5/26/95    RR        #1251403: Multithreading naming support
  21.          <4>     5/25/95    jpa        Removed GetNextWindow, which is now in
  22.                                     Toolbox <Windows.h> [1241078, 1253324]
  23.          <3>     4/14/95    TÇ        With RR & CG: #1194507 DR/BB:title bar of a
  24.                                     draft window doesn't reveal it is a draft
  25.                                     or which draft it is.  Add
  26.                                     AcquireDraftNumFromDraft
  27.          <2>     9/29/94    RA        1189812: Mods for 68K build.
  28.          <1>     6/16/94    RR        first checked in
  29.  
  30.     To Do:
  31.     In Progress:
  32.         
  33. */
  34.  
  35. #ifndef _WINUTILM_
  36. #include "WinUtilM.h" 
  37. #endif
  38.  
  39. #ifndef __LOWMEM__
  40. #include <LowMem.h> // For WindowList global
  41. #endif
  42.  
  43. #ifndef SOM_ODDraft_xh
  44. #include <Draft.xh>
  45. #endif
  46.  
  47. #ifndef SOM_ODDocument_xh
  48. #include <Document.xh>
  49. #endif
  50.  
  51.  
  52. // New Window API uses a new "WindowRef" type as an opaque window type. So that we can compile
  53. // with or without the new Windows.h, define WindowRef if it's not already defined:      --jpa
  54. #ifndef STRICT_WINDOWS
  55. #define WindowRef WindowPeek
  56. #endif
  57.  
  58.  
  59. WindowPtr GetWindowList()
  60. {
  61.     return (WindowPtr)LMGetWindowList();
  62. }
  63.  
  64. void SetWindowList(WindowPtr theWindow)
  65. {
  66.     LMSetWindowList((WindowRef)theWindow); /* Adkins -- changed from WindowPeek to WindowRef */
  67. }
  68.  
  69. void SetNextWindow(WindowPtr theWindow, WindowPtr nextWindow)
  70. {
  71.     ((WindowRecord*) theWindow)->nextWindow = (WindowPeek) nextWindow;
  72. }
  73.  
  74. ODBoolean GetWindowVisible(WindowPtr theWindow)
  75. {
  76.     return (((WindowRecord*) theWindow)->visible ? kODTrue : kODFalse);
  77. }
  78.  
  79. ODBoolean GetWindowHilite(WindowPtr theWindow)
  80. {
  81.     return (((WindowRecord*) theWindow)->hilited ? kODTrue : kODFalse);
  82. }
  83.  
  84. void SetWindowHilite(WindowPtr theWindow, ODBoolean windowHilite)
  85. {
  86.     ((WindowRecord*) theWindow)->hilited = windowHilite;
  87. }
  88.  
  89. RgnHandle GetStructureRegion(WindowPtr theWindow)
  90. {
  91.     return ((WindowRecord*) theWindow)->strucRgn;
  92. }
  93.  
  94. RgnHandle GetContentRegion(WindowPtr theWindow)
  95. {
  96.     return ((WindowRecord*) theWindow)->contRgn;
  97. }
  98.  
  99. ODULong GetDraftNumFromDraft(Environment* ev, ODDraft* draft)
  100. {
  101.   ODULong draftNumber = 0;
  102.   ODDocument* document = draft->GetDocument(ev);
  103.  
  104.   if (document->Exists(ev, 0, draft, kODPosFirstAbove))
  105.   {
  106.      ODDraft* aDraft = document->AcquireBaseDraft(ev, kODDPReadOnly);
  107.      draftNumber = 1;
  108.      while (!ODObjectsAreEqual(ev, aDraft, draft))
  109.      {
  110.        ++draftNumber;
  111.        aDraft = document->AcquireDraft(ev, kODDPReadOnly, 0, aDraft, 
  112.                                        kODPosFirstAbove, kODTrue);
  113.      } 
  114.      ODReleaseObject(ev, aDraft);
  115.   }
  116.   return draftNumber;
  117. }
  118.  
  119. //=====================================================================================
  120. // WindowLink
  121. //=====================================================================================
  122.  
  123. //-------------------------------------------------------------------------------------
  124. // WindowLink::WindowLink
  125. //
  126. // Description
  127. //-------------------------------------------------------------------------------------
  128.  
  129. WindowLink::WindowLink(ODID windowID, ODWindow* window)
  130. {
  131.     fID = windowID;
  132.     fWindow = window;
  133.     fRemove = kODFalse;
  134. }
  135.  
  136. ODBoolean WindowLink::ShouldRemove()
  137. {
  138.     if (fRemove)
  139.         return kODTrue; // Separate line for debugging purposes
  140.     else
  141.         return kODFalse;
  142. }
  143.  
  144. //=====================================================================================
  145. // WindowListIterator - iterates over the Window Manager window list. Iterating from
  146. // back to front using Last/Previous obviously results in several scans of the list,
  147. // as it's a singly-linked list
  148. //=====================================================================================
  149.  
  150.                                                 
  151.  
  152. WindowListIterator::WindowListIterator()
  153. {
  154.     fCurrentWindow = kODNULL;
  155. }  
  156.  
  157. WindowListIterator::~WindowListIterator()
  158. {
  159. }  
  160.  
  161. WindowPtr WindowListIterator::First()
  162. {    
  163.     fCurrentWindow = FrontWindow();
  164.     return fCurrentWindow;
  165. }
  166.  
  167. WindowPtr WindowListIterator::Next()
  168. {
  169.     if (fCurrentWindow)
  170.         fCurrentWindow = (WindowPtr)(((WindowPeek)fCurrentWindow)->nextWindow);
  171.     return fCurrentWindow;
  172. }
  173.  
  174. WindowPtr WindowListIterator::Last()
  175. {    
  176.     fCurrentWindow = FrontWindow();
  177.     if (fCurrentWindow)
  178.     {
  179.         WindowPtr nextWindow = (WindowPtr)(((WindowPeek)fCurrentWindow)->nextWindow);
  180.         while (nextWindow)
  181.         {
  182.             fCurrentWindow = nextWindow;
  183.             nextWindow = (WindowPtr)(((WindowPeek)fCurrentWindow)->nextWindow);
  184.         }
  185.     }
  186.     return fCurrentWindow;
  187. }
  188.  
  189. WindowPtr WindowListIterator::Previous()
  190. {
  191.     WindowPtr savedCurrent = fCurrentWindow;
  192.     
  193.     fCurrentWindow = FrontWindow();
  194.                 
  195.     while (fCurrentWindow && ( (WindowPtr) (((WindowPeek)fCurrentWindow)->nextWindow) != savedCurrent))
  196.     {
  197.             fCurrentWindow = (WindowPtr) (((WindowPeek) fCurrentWindow)->nextWindow);
  198.     }
  199.     return fCurrentWindow;
  200. }
  201.  
  202. ODBoolean WindowListIterator::IsNotComplete()
  203. {
  204.     return (fCurrentWindow != kODNULL);
  205. }  
  206.  
  207.  
  208.  
  209.